import {IMG_PATH} from '../../../../config/index.js'
import { ApiRootUrl } from '../../../../config/index.js'
import Toast from '../../../../@vant/weapp/toast/toast';
import Dialog from '../../../../@vant/weapp/dialog/dialog';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    active:0,
    statusBarHeight:"",
    IMG_PATH:IMG_PATH,
    tabList: [ {
      title: '企业',
    }, {
      title: '招聘',
    }],
    imgurl:`${IMG_PATH}/zhaopinhui/combig.png`,
    tagList:[],
    positionUrl:'',
    companyIntroduction:'',
    companyName:'',
    pendingList: [],
    imageurlList:[],
    videoUrl:'',
    orgCode:''
  },
  namelongTab(event){
    console.log(event);
    Toast(event.currentTarget.dataset.text);
  },
  tabClick(event) {
    this.setData({
      active: event.detail.index,
    },()=>{
      if(this.active == 0){
        this.initCompany();
      }else{
        this.initGanwei();
      }
    })
  },
  pendingDetailsClick(event) {
    console.log(event);
    wx.navigateTo({
      url: `../postdetails/postdetails?id=${event.currentTarget.dataset.id}`,
    })
  },
  initGanwei(){
    let self = this;
    Toast.loading({
      duration: 0,
      message: '加载中...',
      forbidClick: true,
    });
    let params = {
      orgCode:this.data.orgCode,
      id:wx.getStorageSync('zhaopinId')
    }
    wx.request({
      url: `${ApiRootUrl}/hire/getListStation`,
      method: 'get',
      header: {
        'content-type': 'application/json; charset=utf-8',
        'cookie': wx.getStorageSync("sessionid")
      },
      data:params,
      params:params,
      success(res) {
        Toast.clear();
        if(res.data.code == 20000){
          console.log(res.data.data);
          let datalist = res.data.data;
          self.setData({
            pendingList:datalist
          })
        }else{
          Toast({
            duration: 3000,
            forbidClick: true,
            type: 'fail',
            message: res.data.message,
          });
        }
      },
      fail(res){
        Toast.clear();
        Toast({
          duration: 3000,
          forbidClick: true,
          type: 'fail',
          message: '网络已断开',
        });
      }
    })
  },
  initCompany(){
    let self = this;
    Toast.loading({
      duration: 0,
      message: '加载中...',
      forbidClick: true,
    });
    let params = {
      orgCode:this.data.orgCode
    }
    wx.request({
      url: `${ApiRootUrl}/hire/detailsCompany`,
      method: 'get',
      header: {
        'content-type': 'application/json; charset=utf-8',
        'cookie': wx.getStorageSync("sessionid")
      },
      data:params,
      params:params,
      success(res) {
        Toast.clear();
        if(res.data.code == 20000){
          console.log(res.data.data);
          let datalist = res.data.data;
          self.setData({
            companyName:datalist.companyName,
            positionUrl:datalist.companyAddr,
            companyIntroduction:datalist.companyIntroduce,
            imageurlList:datalist.attachmentPicInfo,
            tagList:datalist.tagList,
          })
          if(datalist.attachmentAviInfo && datalist.attachmentAviInfo.length){
            self.setData({
              videoUrl:datalist.attachmentAviInfo[0].attachmentAddr,
            })
          }
        }else{
          Toast({
            duration: 3000,
            forbidClick: true,
            type: 'fail',
            message: res.data.message,
          });
        }
      },
      fail(res){
        Toast.clear();
        Toast({
          duration: 3000,
          forbidClick: true,
          type: 'fail',
          message: '网络已断开',
        });
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log('options-----',options);
    this.setData({
      orgCode:options.orgCode
    })
    this.initCompany();
    wx.setNavigationBarTitle({
      title: options.name
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})